package model

import (
	jsoniter "github.com/json-iterator/go"
	"time"
)

type Job struct {
	ID           uint       `gorm:"primary_key"`
	CreatedAt    time.Time  `json:"createdTime"`
	UpdatedAt    time.Time  `json:"updatedTime"`
	Name         string     `json:"name" gorm:"NOT NULL;UNIQUE"`
	DepartmentId uint       `json:"departmentId"`
	Department   Department `gorm:"ForeignKey:DepartmentId"`
	HasCheck     bool       `json:"hasCheck"`
}

type CustomJob struct {
	ID         uint   `json:"id"`
	Name       string `json:"name"`
	HasCheck   bool   `json:"hasCheck"`
	Department struct {
		ID   uint   `json:"id"`
		Name string `json:"name"`
	} `json:"department"`
}

type JobCopy struct {
	Job
}

func (u *JobCopy) MarshalJSON() ([]byte, error) {
	job := CustomJob{
		ID:   u.ID,
		Name: u.Name,
		HasCheck:u.HasCheck,
	}
	job.Department.Name = u.Department.Name
	job.Department.ID = u.Department.ID
	return jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(job)
}